package cn.lanqiao.pet;

public abstract class Pet {

    //属性（成员变量）
    private String name = "pet";
    private int age;
    private String kind;
    private double price;

    //构造方法
    public Pet() {
        System.out.println("pet 无参构造方法");
    }

    public Pet(int age) {
        this.age = age;
    }

//    public Pet(String kind) {
//        this.kind = kind;
//    }

    public Pet(String name) {
        this.name = name;
    }

    //成员方法
    public void eat(String food) {
        System.out.println(name + "在吃" + food);
    }

    public void sleep() {
        System.out.println(name + "在睡觉");
    }

    public abstract String bark();

    //getter&setter方法

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws Exception {
        if (age > 20 || age < 0) {
            throw new AgeException(age);
        }
        this.age = age;
    }

    public String getKind() {
        return kind;
    }

    @Override
    public String toString() {
        return "Pet{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", kind='" + kind + '\'' +
                ", price=" + price +
                '}';
    }
}
